package dk.au.cs.bdsi.composition;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;

import dk.au.cs.bdsi.composition.activities.NoSuchCompositionException;
import dk.au.cs.bdsi.composition.activities.ReadCompositionActivity;
import dk.au.cs.bdsi.composition.representations.CompositionRepresentation;
import dk.au.cs.bdsi.composition.representations.SecrestURI;

/*import com.restbucks.ordering.activities.NoSuchOrderException;
import com.restbucks.ordering.activities.ReadOrderActivity;
import com.restbucks.ordering.representations.OrderRepresentation;
import com.restbucks.ordering.representations.RestbucksUri;
*/
/** Test class for experimenting with composition
 *  cf rip pp 130
 *  
 * @author Mads Ingstrup
 *
 */
@Path("/secrest")
public class CompositionResource {

    private @Context UriInfo uriInfo;

    public CompositionResource() {
    }

    /**
     * Used in test cases only to allow the injection of a mock UriInfo.
     * 
     * @param uriInfo
     *
    public OrderResource(UriInfo uriInfo) {
        this.uriInfo = uriInfo;  
    }*/

	
	@POST
	@Consumes("application/vnd.bdsi.secrest+xml")
	@Produces("application/vnd.bdsi.secrest+xml")
	public Response getComposition(){
		return null;
	}
	
	/**
	 * Retrieve greeting message
	 * 
	 * @return The string constant "Hello, World!"
	 *
	@GET
    @Path("/{id}")
	@Produces("text/plain")
	public String getMessage() {
		return "Get composition requested at:"+uriInfo.getRequestUri();
	}*/

	
    @GET
    @Path("/{compositionId}")
    @Produces("text/xml") //application/vnd.bdsi.secrestxml")
    public Response getOrder() {
        try {
            CompositionRepresentation responseRepresentation = new ReadCompositionActivity().retrieveByUri(new SecrestURI(uriInfo.getRequestUri()));
            return Response.ok().entity(responseRepresentation).build();
        } catch(NoSuchCompositionException nsoe) {
            return Response.status(Status.NOT_FOUND).build();
        } catch (Exception ex) {
            return Response.serverError().build();
        }
    }
}
